package com.example.demo.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.example.demo.entity.Emp;
import com.example.demo.mapper.EmpMapper;
import com.example.demo.service.EmpService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wangmu on 2018/1/29.
 */
@Service(version = "1.0.0")
public class EmpServiceImpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public Map<String, Object> searchEmpInfoByName(String name, Integer pageNo, Integer pageSize) {
        if(pageNo == null) {
            pageNo = 1;
        }
        if(pageSize == null) {
            pageSize = 10;
        }
        Map<String, Object> result = new HashMap<>();
        PageInfo<Emp> pageInfo = null;
        try {
            PageHelper.startPage(pageNo,pageSize);
            List<Emp> list = empMapper.searchEmpInfoByName(name);
            pageInfo = new PageInfo<>(list);
            if(list.isEmpty()) {
                result.put("status","1000");
            } else {
                result.put("status","0000");
                result.put("message","成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.put("status","4000");
            return result;
        }
        HashMap<String, Object> data = new HashMap<>();
        result.put("total",pageInfo.getTotal());
        result.put("data",pageInfo.getList());
        return result;
    }


}
